package com.lvyq.qrobot;

import com.lvyq.qrobot.util.CommonUtil;
import org.jsoup.Jsoup;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;

/**
 * @author lvyq
 * @version 1.0
 * Create by 2024-06-25 17:04
 */
public class ChuanYueUtil {


    //签到
    public static String sing(int i,String tkn){
        String singContent="";
        try {
            String SING="http://game.qqhome.cn/mergecyhc5/giftbag/signin_w2.jsp?i="+i+"&tkn="+tkn;
            String res = sendGet(SING);
            String text = Jsoup.parse(res).body().getElementsByClass("module-content").text();
            singContent = text.split("今日可领奖次数")[0].split("提示:")[1];
            System.out.println("签到end...\n=============");
            singContent="[CQ:face,big=true,id=319]"+singContent;
        }catch (Exception e){
            System.out.println("签到异常");
        }

        return singContent;
    }

    public static String shangchao(int i,String tkn){
        String content="";
        try {
            String SING= "http://game.qqhome.cn/mergecyhc5/job/shangchao_w2.jsp?i="+i+"&tkn="+tkn;
            String res  = Jsoup.parse(sendGet(SING)).text();
            content = res.split("获得:")[1].split("返回首页")[0].trim();
            content="[CQ:face,big=true,id=346]上朝:"+content;
        }catch (Exception e){
            System.out.println("上朝异常");
        }

        return content;
    }

    //天梯
    public static String jingji(int i,String tkn){
        String content="";
        try {
            String res = sendGet("http://game.qqhome.cn/mergecyhc5/match/reward_w2.jsp?i="+i+"&tkn="+tkn+"&r=1");
            res  = Jsoup.parse(res).text();
            content = res.split("恭喜你!获得")[1].split("返回上页")[0].trim();
            content="[CQ:face,big=false,id=332]天梯:"+content;
        }catch (Exception e){
            System.out.println("竞技奖励领取异常");
        }

        return content;
    }


    //抽奖
    public static String choujiang(int i,String tkn){
        StringBuffer buffer = new StringBuffer();
        Integer integer = CommonUtil.randomNum(9);
        String chou = "http://game.qqhome.cn/mergecyhc5/giftbag/signin_w2.jsp?i="+i+"&tkn="+tkn+"&d="+integer;
        buffer.append("[CQ:face,big=false,id=293]抽奖:");
        try{
        String text1  = Jsoup.parse(sendGet(chou)).text();
        text1=text1.split("提示:恭喜你从众多宝物中抽到了")[1].split("------------------")[0].trim();
        buffer.append(text1);
        System.out.println(text1);
        }catch (Exception e){
            System.out.println("抽奖异常");
        }
        try{
            Integer integer2 = CommonUtil.randomNum(9);
            while (integer==integer2){
                integer2=CommonUtil.randomNum(9);
            }
            chou = "http://game.qqhome.cn/mergecyhc5/giftbag/signin_w2.jsp?i="+i+"&tkn="+tkn+"&d="+integer2;
            String text2 = Jsoup.parse(sendGet(chou)).text().split("提示:恭喜你从众多宝物中抽到了")[1].split("------------------")[0].trim();
            buffer.append("、"+text2);
            System.out.println(text2);
        }catch (Exception e){
            System.out.println("没有第二次抽奖机会");
        }

        return buffer.toString();
    }

    public static String yaoqian(int i,String tkn){
        try {
            String yao="http://game.qqhome.cn/mergecyhc5/money/money_w2.jsp?i="+i+"&tkn="+tkn+"&t=1";
            String content  = Jsoup.parse(sendGet(yao)).text();
            content=content.split("掉入了你的钱包,您获得了")[1].split("活动期间")[0].trim();
            content="[CQ:face,big=true,id=345]摇钱:"+content;
            return content;
        }catch (Exception e){
            System.out.println("摇钱异常");
        }
        return "";
    }
    public static String sendGet(String url) {
        String result = "";
        BufferedReader in = null;

        try {
            String urlNameString = url;
            java.net.URL realUrl = new URL(urlNameString);
            URLConnection connection = realUrl.openConnection();
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            connection.connect();
            Map<String, List<String>> map = connection.getHeaderFields();
            Iterator var8 = map.keySet().iterator();

            while(var8.hasNext()) {
                String key = (String)var8.next();
                //  System.out.println(key + "--->" + map.get(key));
            }

            String line;
            for(in = new BufferedReader(new InputStreamReader(connection.getInputStream())); (line = in.readLine()) != null; result = result + line) {
            }
        } catch (Exception var18) {
            System.out.println("发送GET请求出现异常！" + var18);
            var18.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception var17) {
                var17.printStackTrace();
            }

        }

        return result;
    }


    public static void main(String[] args) {
        int i=22167973;
        String tkn="Ybk_aD00p9a9LwqbLBanGD6Hetb3na5PiWloaHMXu3Y";
        StringBuffer buffer = new StringBuffer();
        String sing = sing(i, tkn);
        String choujiang = choujiang(i, tkn);
        String shangchao = shangchao(i, tkn);
        String jingji = jingji(i, tkn);
        String yaoqian = yaoqian(i, tkn);
        buffer.append(sing)
                .append("\n"+shangchao)
                .append("\n"+choujiang)
                .append("\n"+jingji)
                .append("\n"+yaoqian);
        System.out.println("结果》》》》\n"+buffer);

    }

    public static void lao(int i,String tnk){
        ChuanYueUtil.sendGet("http://game.qqhome.cn/mergecyhc5/prison/laofang/kaishi_w2.jsp?i="+i+"&tkn="+tnk);
        while (true){
            Date date = new Date();
            int hours = date.getHours();
            if (hours>13){
                return;
            }
            for (int j = 1; j < 41; j++) {
                String aa="http://game.qqhome.cn/mergecyhc5/prison/laofang/fight_w2.jsp?i="+i+"&tkn="+tnk+"&mid="+j+"&lx=y";
                String s = ChuanYueUtil.sendGet(aa);
                String text = Jsoup.parse(s).text();
                if (text.contains("你将拷问牢头成功击杀") ){
                    System.out.println(j+">>>>>>"+text);
                }
            }
            for (int j = 1; j < 11; j++) {
                ChuanYueUtil.sendGet("http://game.qqhome.cn/mergecyhc5/prison/laofang/pk_w2.jsp?i="+i+"&tkn="+tnk+"&a=y&mid="+j);
            }
        }

    }
}
